#include "events_base.hpp"
#include "events_cb.hpp"
#include <cassert>
#include <cstring>
#include <event2/listener.h>
#define PORT 5001
events_base::events_base(/* args */)
{
    memset(&m_sin,0,sizeof(m_sin));
    m_sin.sin_family = AF_INET;
    m_sin.sin_port = htons(PORT);
}

events_base::~events_base()
{
    event_base_free(m_base);
    evconnlistener_free(m_ev);
}
void events_base::event_init()
{
    m_base = event_base_new();
    if(!m_base)
    {
        return;
    }
    m_ev = evconnlistener_new_bind(m_base,
    events_cb::event_cb,
    m_base,
    LEV_OPT_REUSEABLE|LEV_OPT_CLOSE_ON_FREE,
    10,
    (sockaddr*)&m_sin,
    sizeof(m_sin));
    if(!m_ev)
    {
        return;
    }
}
void events_base::event_run()
{
    event_base_dispatch(m_base);

}